package a10_动态规划;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * <p>
 * a41_最长递增子序列复习4
 * </p>
 *
 * @author flyduck
 * @since 2025/5/7
 */
public class a41_最长递增子序列复习4 {

    public static void main(String[] args) {
        System.out.println(lengthOfLIS(new int[]{1,3,6,7,9,4,10,5,6}));
    }
    //dp[i]：以nums[i]作为递增子序列的结尾的最长长度

    //递推公式：
    //dp[i] = dp[j] + 1;

    //初始化：
    //dp[0] = 1;
    public static int lengthOfLIS(int[] nums) {
        int[] dp = new int[nums.length];
        Arrays.fill(dp, 1);

        int result = Integer.MIN_VALUE;
        for (int i = 1; i < nums.length; i++) {
            for (int j = 0; j < i; j++) {
                if(nums[i] > nums[j]){
                    dp[i] = Math.max(dp[i], dp[j] + 1);
                }
            }
            result = Math.max(result, dp[i]);
        }

        return result == Integer.MIN_VALUE ? 1 : result;
    }
}
